package com.fancy.learncenter.view;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.listener.CustomListener;
import com.fancy.learncenter.adapter.ConditionAdapter;
import com.fancy.learncenter.common.MyApplication;
import com.superservice.lya.R;

import java.util.ArrayList;

/**
 * Created by hyy on 2018/2/25.
 * Explain activity as
 */

public class PopupWindowSalary extends BasedPopupWindow {


    View locationView;

    View popopView;
    View viewParent;

    RecyclerView recyclerView;
    ArrayList<String> itemDatas;

    Activity mContext;

    public PopupWindowSalary(Activity mContext, View viewParent, ArrayList<String> itemDatas) {
        super(mContext);
        this.mContext = mContext;
        this.viewParent = viewParent;
        this.locationView = locationView;
        popopView = LayoutInflater.from(MyApplication.context).inflate(R.layout.pupopwinodw_salary, null);
        this.itemDatas = itemDatas;
        initPopupWionw();
    }

    private void initPopupWionw() {
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
//        this.setOutsideTouchable(true);

        recyclerView = (RecyclerView) popopView.findViewById(R.id.recycleView);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        conditionAdapter = new ConditionAdapter(mContext, itemDatas);
        recyclerView.setAdapter(conditionAdapter);

        popopView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupWindowSalary.this.dismiss();
            }
        });

        this.update();

        this.setContentView(popopView);

    }

    ConditionAdapter conditionAdapter;

//    public void showPopupWindow() {
//        showAsDropDown(viewParent);
//    }


    @Override
    public void showPopupWindow() {
        super.showPopupWindow();
        showAsDropDown(viewParent);
    }

    public void setClickCallBack(ClickCallBack clickCallBack) {
        this.clickCallBack = clickCallBack;

        conditionAdapter.setClickCallBack(new ConditionAdapter.ClickCallBack() {
            @Override
            public void clickCallBack(String content) {
                PopupWindowSalary.this.clickCallBack.selecCallBack(content);
                PopupWindowSalary.this.dismiss();
            }
        });
    }


    @Override
    public void dismiss() {
        super.dismiss();
        if (clickCallBack != null) {
            clickCallBack.cancleCallBack();
        }
    }

    private ClickCallBack clickCallBack;

    public interface ClickCallBack {
        abstract void cancleCallBack();

        abstract void selecCallBack(String content);
    }

    private void getPick() {

    }


}
